' Copyright (c) $Year$ DotNetNuke Corporation
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 


Imports DotNetNuke
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Entities.Modules



    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' The EditGeminorumSoftwareContacts class is used to manage content
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Partial Class Edit
        Inherits GeminorumSoftwareContactsModuleBase

#Region "Private Members"

#End Region

#Region "Event Handlers"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Page_Load runs when the control is loaded
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
            If Page.IsPostBack = False Then
                If ContactID > 0 Then
                    SetCmdDeleteState(True)

                    Dim contact As Contact = ContactController.GetContact(ContactID)
                    txtCellPhone.Text = contact.CellPhoneNumber
                    txtEmail.Text = contact.Email
                    txtName.Text = contact.Name
                    txtPhone.Text = contact.PhoneNumber
                    txtTitle.Text = contact.Title
                Else
                    SetCmdDeleteState(False)
                End If
            End If
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region

    Private Sub SetCmdDeleteState(State As Boolean)
        cmdDelete.Enabled = State
        cmdDelete.Visible = State
    End Sub

    Private Sub cmdCancel_Click(sender As Object, e As System.EventArgs) Handles cmdCancel.Click
        Response.Redirect(DotNetNuke.Common.Globals.NavigateURL)
    End Sub

    Private Sub cmdSubmit_Click(sender As Object, e As System.EventArgs) Handles cmdSubmit.Click
        Dim contact As Contact

        If ContactID > 0 Then
            contact = ContactController.GetContact(ContactID)
        Else
            contact = New Contact
        End If

        contact.CellPhoneNumber = txtCellPhone.Text.Trim
        contact.Email = txtEmail.Text.Trim
        contact.ModuleID = ModuleId
        contact.Name = txtName.Text.Trim
        contact.PhoneNumber = txtPhone.Text.Trim
        contact.Title = txtTitle.Text.Trim

        ContactController.SaveContact(contact, TabId)

        Response.Redirect(DotNetNuke.Common.Globals.NavigateURL)
    End Sub

    Private Sub cmdDelete_Click(sender As Object, e As System.EventArgs) Handles cmdDelete.Click
        ContactController.DeleteContact(ContactID)
        Response.Redirect(DotNetNuke.Common.Globals.NavigateURL)
    End Sub
End Class